<template>
  <div class="app-container">
    <!--按钮-->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['teacher:train:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['teacher:train:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['teacher:train:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['teacher:train:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getTrainInfo"></right-toolbar>
    </el-row>
    <!--表格-->
    <el-table border :data="trainList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column fixed label="培训类别" align="center" prop="a1101" width="120"/>
      <el-table-column fixed label="培训主办单位名称" align="center" prop="a1114b" width="150"/>
      <el-table-column fixed label="培训主办单位级别" align="center" prop="a1117" width="150"/>
      <el-table-column fixed label="培训班名称" align="center" prop="a1131" width="120"/>
      <el-table-column label="培训机构类别/从学单位" align="center" prop="a1127" width="180"/>
      <el-table-column label="培训班类别" align="center" prop="a1134" width="120"/>
      <el-table-column label="培训学时" align="center" prop="a1156" width="120"/>
      <el-table-column label="培训形式" align="center" prop="zdyxa1102" width="120"/>
      <el-table-column label="培训内容" align="center" prop="zdyxa1103" width="120"/>
      <el-table-column label="培训期限" align="center" prop="zdyxa1105" width="120"/>
      <el-table-column label="培训主办单位类别" align="center" prop="zdyxa1106" width="150"/>
      <el-table-column label="培训机构名称/从学单位" align="center" prop="a1118b" width="180"/>
      <el-table-column label="培训承办单位" align="center" prop="zdyxa1108" width="120"/>
      <el-table-column label="培训专业名称" align="center" prop="a1137" width="120"/>
      <el-table-column label="培训专业类别" align="center" prop="a1141" width="120"/>
      <el-table-column label="培训起始日期" align="center" prop="a1107" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.a1107, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="培训结束日期" align="center" prop="a1111" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.a1111, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="综合评价" align="center" prop="zdyxa1124" width="120"/>
      <el-table-column fixed="right" label="附件" align="center" prop="remark" width="200">
        <template slot-scope="{row}">
          <el-link :href="row.remark" target="_blank" class="buttonText"  type="primary" :underline="false">{{row.remark}}</el-link>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-info"
            @click="handleDetail(scope.row)"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['teacher:train:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['teacher:train:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页插件-->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getTrainInfo"
    />

    <!-- 添加或修改培训情况对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form v-bind:disabled="disabled" ref="form" :model="form" :rules="rules">
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="本人编号" prop="a00">
              <el-input v-model="form.a00" placeholder="请输入本人编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="培训类别" prop="a1101">
              <el-select v-model="form.a1101" placeholder="请选择培训类别">
                <el-option
                  v-for="dict in a1101Options"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="培训起始日期" prop="a1107">
              <el-date-picker clearable size="small"
                              v-model="form.a1107"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择培训起始日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="培训结束日期" prop="a1111">
              <el-date-picker clearable size="small"
                              v-model="form.a1111"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择培训结束日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="培训主办单位名称" prop="a1114b">
              <el-input v-model="form.a1114b" placeholder="请输入培训主办单位名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="培训主办单位级别" prop="a1117">
              <el-input v-model="form.a1117" placeholder="请输入培训主办单位级别" />
            </el-form-item>
          </el-col>
        </el-row>
<!--        <el-form-item label="培训主办单位名称补充" prop="a1114a">-->
<!--          <el-input v-model="form.a1114a" placeholder="请输入培训主办单位名称补充" />-->
<!--        </el-form-item>-->
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="培训班名称" prop="a1131">
              <el-input v-model="form.a1131" placeholder="请输入培训班名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="培训机构类别/从学单位" prop="a1127">
              <el-input v-model="form.a1127" placeholder="请输入培训机构类别/从学单位" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="培训班类别" prop="a1134">
              <el-input v-model="form.a1134" placeholder="请输入培训班类别" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="培训学时" prop="a1156">
              <el-input v-model="form.a1156" placeholder="请输入培训学时" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="培训形式" prop="zdyxa1102">
              <el-input v-model="form.zdyxa1102" placeholder="请输入培训形式" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="培训内容" prop="zdyxa1103">
              <el-input v-model="form.zdyxa1103" placeholder="请输入培训内容" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="培训期限" prop="zdyxa1105">
              <el-input v-model="form.zdyxa1105" placeholder="请输入培训期限" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="培训主办单位类别" prop="zdyxa1106">
              <el-input v-model="form.zdyxa1106" placeholder="请输入培训主办单位类别" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="培训机构名称/从学单位" prop="a1118b">
              <el-input v-model="form.a1118b" placeholder="请输入培训机构名称/从学单位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="培训承办单位" prop="zdyxa1108">
              <el-input v-model="form.zdyxa1108" placeholder="请输入培训承办单位" />
            </el-form-item>
          </el-col>
        </el-row>
<!--        <el-form-item label="培训机构名称补充/从学单位" prop="a1118a">-->
<!--          <el-input v-model="form.a1118a" placeholder="请输入培训机构名称补充/从学单位" />-->
<!--        </el-form-item>-->

        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="培训专业名称" prop="a1137">
              <el-input v-model="form.a1137" placeholder="请输入培训专业名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="培训专业类别" prop="a1141">
              <el-input v-model="form.a1141" placeholder="请输入培训专业类别" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="综合评价" prop="zdyxa1124">
              <el-input v-model="form.zdyxa1124" placeholder="请输入综合评价" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
          </el-col>
        </el-row>
        <el-form-item label="附件" prop="remark">
          <fileUpload v-model="form.remark"/>
        </el-form-item>
<!--        <el-form-item label="培训承办单位" prop="zdyxa1108Text">-->
<!--          <el-input v-model="form.zdyxa1108Text" placeholder="请输入培训承办单位" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="删除标识" prop="delFlag">-->
<!--          <el-input v-model="form.delFlag" placeholder="请输入删除标识" />-->
<!--        </el-form-item>-->
      </el-form>
      <div v-show="!hidden" slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTrain, getTrain, delTrain, addTrain, updateTrain, exportTrain } from "@/api/teacher/train";
import {selectTrainByA00} from "@/api/teacher/person";
import FileUpload from "@/components/FileUpload";

export default {
  name: "Train",
  components: {
    FileUpload
  },
  data() {
    return {
      hidden: false,
      //禁用状态
      disabled: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 培训情况表格数据
      trainList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 培训类别字典
      a1101Options: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        a00: null,
        a1131: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getTrainInfo();
    this.getDicts("sys_person_training").then(response => {
      this.a1101Options = response.data;
    });
  },
  methods: {
    /** 查询培训情况列表 */
    getTrainInfo() {
      this.A00 = this.$route.query.A00
      selectTrainByA00(this.A00).then((response) => {
        this.trainList = response.rows;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        recordid: null,
        a00: null,
        a1101: null,
        a1107: null,
        a1111: null,
        a1114b: null,
        a1114a: null,
        a1117: null,
        a1131: null,
        a1127: null,
        a1134: null,
        a1156: null,
        zdyxa1102: null,
        zdyxa1103: null,
        zdyxa1105: null,
        zdyxa1106: null,
        a1118a: null,
        a1118b: null,
        zdyxa1108: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
        remark: null,
        a1137: null,
        a1141: null,
        zdyxa1124: null,
        zdyxa1108Text: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getTrainInfo();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.recordid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加培训情况";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.disabled = false
      this.hidden = false;
      this.reset();
      const recordid = row.recordid || this.ids
      getTrain(recordid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改培训情况";
      });
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      this.hidden = true;
      this.disabled = true;
      this.reset();
      const recordid = row.recordid || this.ids
      getTrain(recordid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "培训情况详情";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.recordid != null) {
            updateTrain(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getTrainInfo();
            });
          } else {
            addTrain(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getTrainInfo();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const recordids = row.recordid || this.ids;
      this.$confirm('是否确认删除培训情况编号为"' + recordids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delTrain(recordids);
        }).then(() => {
          this.getTrainInfo();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有培训情况数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportTrain(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
